#include"../xxxpcsc/xxxpcsc.h"
#include<unistd.h>
xxXPCSC::Logger::ptr g_logger = XXXPCSC_LOG_ROOT();

int count = 0;
xxXPCSC::RWMutex s_mutex;
void func1(){
    XXXPCSC_LOG_INFO(g_logger)<<"name: "<<xxXPCSC::Thread::GetName()<<" this.name: "<<xxXPCSC::Thread::GetThis()->getName()
                                <<" id: "<<xxXPCSC::GetThreadId()<<" this.id: "<<xxXPCSC::Thread::GetThis()->getId();

    for(int i=0;i<1000000;i++){
        xxXPCSC::RWMutex::WriteLock lock(s_mutex);
        count++;
    }
}

void func2(){

}

int main(){
    std::vector<xxXPCSC::Thread::ptr> thrs;
    XXXPCSC_LOG_INFO(g_logger)<<"thread test begin";
    for(int i=0;i<5;i++){
        xxXPCSC::Thread::ptr thr(new xxXPCSC::Thread(&func1,"name_"+std::to_string(i)));
        thrs.push_back(thr);
    }


    for(int i=0;i<5;i++){
        thrs[i]->join();
    }

    XXXPCSC_LOG_INFO(g_logger)<<"thread test end";
     XXXPCSC_LOG_INFO(g_logger)<<"count= "<<count;
    return 0;

}